package com.cskaoyan.processor;

import com.cskaoyan.util.ProxyUtil;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.config.BeanPostProcessor;
import org.springframework.stereotype.Component;

/**
 * @author stone
 * @date 2022/03/21 18:07
 */
@Component
public class ServiceProxyBeanPostProcessor implements BeanPostProcessor {
    @Override
    public Object postProcessBeforeInitialization(Object bean, String beanName) throws BeansException {
        if (beanName.toLowerCase().endsWith("serviceimpl")) {
//            Object proxy = ProxyUtil.getServiceProxy(bean);
            Object proxy = ProxyUtil.getServiceProxy(bean.getClass());
            return proxy;
        }
        return null;
    }
}
